package com.example.fw;

import org.hibernate.Session;
import org.hibernate.Transaction;

import com.example.utils.SortedListOf;

public class HibernateHelper extends HelperBase
{

	public HibernateHelper(ApplicationManager manager)
	{
		super(manager);
	}

	public SortedListOf<User> getUsers()
	{
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction trans = session.beginTransaction();
		try
		{
			return new SortedListOf<User>(
					session.createQuery("from User").list());
		}
		finally
		{
			trans.commit();
		}
	}

	public boolean isUserCreated(User user)
	{
		SortedListOf<User> users = getUsers();

		for (User someUser : users)
		{
			if (someUser.getLogin().equals(user.getLogin()))
				return true;
		}
		return false;
	}
}